from Registry import Registry
import os, urllib

class Common:
	def make_url(self, url):
		tmp = urllib.parse.urlparse(url)

		#todo переделать под питон
		url = {'scheme': tmp.scheme, 'host': tmp.netloc, 'path': tmp.path, 'query': tmp.query, 'full': url}

		return url

	def clear_path(self, path):
		while path.find('//') != -1:
			path = path.replace('//', '/')
		return path

	def mongo_result_to_list(mongo_result):
		result = []
		for row in mongo_result:
			result.append(row)
		return result

	def clear_pages_data(self, map):
		for file in os.listdir(Registry.get('data_path') + map):
			if not os.path.isfile(Registry.get('data_path') + map + '/' + file):
				continue
			os.remove(Registry.get('data_path') + map + '/' + file)

